package com.onix.actions;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class OnixApplication extends Activity {
	private EtwasAdapter mHelper;
	private int lastOrienration = 666;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mHelper = new EtwasAdapter(this);

		changeBackgroundOrientation(
				getResources().getConfiguration().orientation,
				R.drawable.bg_main_v, R.drawable.bg_main_h);

	}

	public void changeBackgroundOrientation(int outerOrientation,
			int inBgPortret, int inBgLandscape) {
		if (lastOrienration != outerOrientation) {
			if (outerOrientation == Configuration.ORIENTATION_LANDSCAPE) {
				this.getWindow().setBackgroundDrawableResource(inBgLandscape);
			} else {
				this.getWindow().setBackgroundDrawableResource(inBgPortret);
			}
			lastOrienration = outerOrientation;
		}
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		changeBackgroundOrientation(newConfig.orientation,
				R.drawable.bg_main_v, R.drawable.bg_main_h);
		super.onConfigurationChanged(newConfig);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_base, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return mHelper.selectMenu(item.getItemId());
	}
}